package cn.hr.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import javax.annotation.Resource;

import cn.hr.dao.mapper.ArchivesMapper;
import cn.hr.dao.mapper.PayrollDetailMapper;
import cn.hr.dao.mapper.PayrollOMapper;
import cn.hr.dao.mapper.PostMapper;
import cn.hr.dao.mapper.SalProStanMapper;
import cn.hr.dao.mapper.SalaryStandardMapper;
import cn.hr.pojo.PayrollDetail;
import cn.hr.pojo.PayrollO;
import cn.hr.pojo.SalaryStandard;
import cn.hr.utils.Constants;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import cn.hr.dao.mapper.PayrollCrewMapper;
import cn.hr.pojo.PayrollCrew;
import cn.hr.service.PayrollCrewService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 组织人员工资单服务接口实现类
 *
 * @author MO
 */
@CacheConfig(cacheNames = "payrollCrew")
@Scope("prototype")
@Service("payrollCrewService")
public class PayrollCrewServiceImpl implements PayrollCrewService {
    @Resource
    private PayrollCrewMapper payrollCrewMapper;
    @Resource
    private ArchivesMapper archivesMapper;
    @Resource
    private PayrollDetailMapper payrollDetailMapper;
    @Resource
    private PayrollOMapper payrollOMapper;
    @Resource
    private SalaryStandardMapper salaryStandardMapper;
    @Resource
    private SalProStanMapper salProStanMapper;

    @Override
    public boolean insert(PayrollCrew t) throws Exception {
        return false;
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public boolean insert(Integer poId) throws Exception {
        return false;
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public boolean update(List<PayrollCrew> payrollCrews, List<PayrollDetail> payrollDetails) throws Exception {
        return false;
    }

    @Override
    public boolean update(PayrollCrew t) throws Exception {
        return false;
    }

    @Override
    public boolean delete(Integer id) throws Exception {
        return false;
    }

    @Override
    public PayrollCrew get(Integer id) throws Exception {
        return payrollCrewMapper.get(id);
    }

    @Override
    public PageInfo<Map> findListByCondition(Map m, int pageNo) throws Exception {
        PageHelper.startPage(pageNo, Constants.PAGESIZE);
        List<Map> list = payrollCrewMapper.findListByCondition(m);
        Map detailCondition = new HashMap();
        Set<String> headSet = new LinkedHashSet<String>();
        for (Map crew : list) {
            detailCondition.put("crewId", crew.get("id"));
            List<Map> detailMap = payrollDetailMapper.findListByCondition(detailCondition);
            for (Map detail : detailMap) {
                headSet.add(String.valueOf(detail.get("name")));
            }
            crew.put("detailMap", detailMap);
        }
        m.put("headSet", headSet);
        list.add(m);
        return new PageInfo<Map>(list);
    }

    @Override
    public Long findCountByCondition(Map m) throws Exception {
        return payrollCrewMapper.findCountByCondition(m);
    }
}
